<% layout('/layouts/default.html', {title: '广告管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa fa-list-alt"></i> ${text('广告计划管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(isAgent == 1 ){ %>
					<% if(hasPermi('ad:ad:edit')){ %>
						<a href="${ctx}/ad/ad/form" class="btn btn-default btnTool" title="${text('新增广告')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
					<% } %>
				<% } %>
				<div class="btn-group">
					<a href="javascript:" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
						<i class="fa fa-navicon"></i> <span class="caret"></span>
					</a>
					<ul class="dropdown-menu">
						<li><a href="javascript:" id="btnExport"><i class="glyphicon glyphicon-export"></i> 导出</a></li>
					</ul>
				</div>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${ad}" action="${ctx}/ad/ad/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<#form:input path="id" maxlength="64" class="form-control width-120" style ="display:none"/>
				<div class="form-group">
					<label class="control-label">${text('广告计划名称')}：</label>
					<div class="control-inline">
						<#form:input path="name" maxlength="200" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('投放终端')}：</label>
					<div class="control-inline width-120">
						<#form:select path="terminal" dictType="ad_terminal" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('广告类型')}：</label>
					<div class="control-inline width-120">
						<#form:select path="type" dictType="ad_type" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('广告形式')}：</label>
					<div class="control-inline width-120">
						<#form:select path="shape" dictType="ad_shape" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('落地页形式')}：</label>
					<div class="control-inline width-120">
						<#form:select path="urlType" dictType="ad_url_type" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('落地页URL')}：</label>
					<div class="control-inline">
						<#form:input path="url" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('状态')}：</label>
					<div class="control-inline width-120">
						<#form:select path="status" dictType="sys_search_status" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('广告主')}：</label>
					<div class="control-inline width-120" >
						<#form:input path="adVertiser.account" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('投放媒体')}：</label>
					<div class="control-inline">
						<#form:input path="mediaName" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('媒体页URL')}：</label>
					<div class="control-inline">
						<#form:input path="mediaUrl" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('广告位ID')}：</label>
					<div class="control-inline">
						<#form:input path="adLocationId" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('广告页曝光量')}：</label>
					<div class="control-inline">
						<#form:input path="adExposureNum" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('广告页点击量')}：</label>
					<div class="control-inline">
						<#form:input path="adClickNum" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('广告页点击率')}：</label>
					<div class="control-inline">
						<#form:input path="adClickRate" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('落地页展示量')}：</label>
					<div class="control-inline">
						<#form:input path="ldShowNum" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
                <div class="form-group">
                    <label class="control-label">${text('获客数量')}：</label>
                    <div class="control-inline width-120">
                        <#form:input path="guestNum" maxlength="255" class="form-control width-120"/>
                    </div>
                </div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("广告计划名称")}', name:'name', index:'a.name', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return '<a href="${ctx}/ad/ad/details?id='+row.id+'" class="btnList" data-title="${text("查看广告计划")}">'+(val||row.id)+'</a>';
		}},
		{header:'${text("投放终端")}', name:'terminal', index:'a.terminal', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('ad_terminal')}, val, '${text("未知")}', true);
		}},
		{header:'${text("广告类型")}', name:'type', index:'a.type', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('ad_type')}, val, '${text("未知")}', true);
		}},
		{header:'${text("广告形式")}', name:'shape', index:'a.shape', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('ad_shape')}, val, '${text("未知")}', true);
		}},
		{header:'${text("落地页形式")}', name:'urlType', index:'a.url_type', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('ad_url_type')}, val, '${text("未知")}', true);
		}},
		{header:'${text("落地页URL")}', name:'url', index:'a.url', width:150, align:"center", formatter: function(val, obj, row, act){
        	if(row.url != null && row.url != ''){
        		return '<a href="'+row.url+'";>'+row.url+'</a>&nbsp;';
        	}else{
        		return '';
        	}
		}},
		{header:'${text("广告主")}', name:'adVertiser.account', index:'u10.account', width:150, align:"center"},
        {header:'${text("投放媒体")}', name:'mediaName', index:'a.media_name', width:150, align:"left"},
        {header:'${text("媒体页URL")}', name:'mediaUrl', index:'a.media_url', width:150, align:"center", formatter: function(val, obj, row, act){
        	if(row.mediaUrl != null && row.mediaUrl != ''){
        		return '<a href="'+row.mediaUrl+'";>'+row.mediaUrl+'</a>&nbsp;';
        	}else{
        		return '';
        	}
        }},
        {header:'${text("广告位ID")}', name:'adLocationId', index:'a.ad_location_id', width:150, align:"left"},
        {header:'${text("广告页曝光量")}', name:'adExposureNum', index:'a.ad_exposure_num', width:150, align:"left"},
        {header:'${text("广告页点击量")}', name:'adClickNum', index:'a.ad_click_num', width:150, align:"left"},
        {header:'${text("广告页点击率")}', name:'adClickRate', index:'a.ad_click_rate', width:150, align:"left"},
        {header:'${text("落地页展示量")}', name:'ldShowNum', index:'a.ld_show_num', width:150, align:"left"},
        {header:'${text("获客数量")}', name:'guestNum', index:'a.guestNum', width:150, align:"left", sortable:false, frozen:true, formatter: function(val, obj, row, act){
                return '<a href="${ctx}/ad/adGuest/listByAd?adName='+row.name+'&adId='+row.id+'" class="btnList" data-title="${text("获客管理")}">'+(val||row.guestNum)+'</a>';
        }},
        {header:'${text("操作")}', name:'actions', width:200, sortable:false, title:false, formatter: function(val, obj, row, act){
            var actions = [];
        <% if(hasPermi('ad:ad:edit')){ %>
                actions.push('<a href="${ctx}/ad/ad/form?id='+row.id+'" class="btnList" title="${text("编辑广告")}"><i class="fa fa-pencil"></i></a>&nbsp;');
                if (row.status == Global.STATUS_NORMAL){
                    actions.push('<a href="${ctx}/ad/ad/disable?id='+row.id+'" class="btnList" title="${text("停用广告")}" data-confirm="${text("确认要停用该广告吗？")}"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
                }
                if (row.status == Global.STATUS_DISABLE){
                    actions.push('<a href="${ctx}/ad/ad/enable?id='+row.id+'" class="btnList" title="${text("启用广告")}" data-confirm="${text("确认要启用该广告吗？")}"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;');
                }
                actions.push('<a href="${ctx}/ad/ad/delete?id='+row.id+'" class="btnList" title="${text("删除广告")}" data-confirm="${text("确认要删除该广告吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
            <% } %>
            return actions.join('');
        }},
		{header:'${text("状态")}', name:'status', index:'a.status', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('sys_search_status')}, val, '${text("未知")}', true);
		}},
		{header:'${text("更新时间")}', name:'updateDate', index:'a.update_date', width:150, align:"center"},
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});

$('#btnExport').click(function(){
    js.ajaxSubmitForm($('#searchForm'), {
        url:'${ctx}/ad/ad/exportData',
        downloadFile:true
    });
});

$(function(){
	$("th").attr("height","55px!important");
});
</script>